<?php
/**
 *
 */
class Priority extends AppModel {
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';

	# Validation rules.
    var $validate = array(
        'name' => array(
            'notNull' =>array(
    		   'rule' => 'notEmpty',
    		   'required' => true,
    		   'message' => 'The Priority Name must not be null and it is required',
    		   'last' => true
    		)
		)
	);
    

/**
 * hasMany associations
 *
 * @var array
 */

    public $hasMany = array(
        'Ticket' => array(
            'className' => 'Ticket',
            'foreignKey' => 'priority_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        ),
        'TicketHistory' => array(
            'className' => 'TicketHistory',
            'foreignKey' => 'priority_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );
    
    
    
    /**
     * This function retrieves all the users from the database tables users.
     * @name getAllUsers
     * @param void
     * @return mixed. Array containing the data retrieved.
     * @access public
     */
    function get(){
        return $this->find('all',array(
            'conditions'=>array('deleted'=>'n'),
            'recursive'=>-1
        ));
    }

    function getPriorityById($id = null){
        $conditions = array(
           'Priority.id' => $id,
           'Priority.deleted' => 'n'
        );
        # fetch the specific data from the server and retrun it.
        return  $this->find('first', array('conditions' => $conditions, 'recursive' => 1));
    }
}
